<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up() : void
  {
    Schema::create('system_resource', function (Blueprint $table) {
      $table->id()->comment('自增编号');
      $table->unsignedInteger('organization_id')->comment('机构编号')->default(0);
      $table->string('name', 64)->comment('文件名称')->default('');
      $table->unsignedInteger('size')->comment('文件大小')->default(0);
      $table->string('mimetype', 64)->comment('资源类型')->default('');
      $table->string('extension', 10)->comment('文件后缀')->default('');
      $table->string('url', 250)->comment('文件地址')->default('');
      $table->string('hash', 32)->comment('文件哈希值')->default('');
      $table->unsignedTinyInteger('status')->comment('状态 1:正常, 2:异常, -1:删除')->default(1);
      $table->unsignedInteger('create_time')->comment('创建时间')->default(0);
      $table->unsignedInteger('update_time')->comment('更新时间')->default(0);

      $table->index(['hash', 'status']);
      $table->index('organization_id');
    });
  }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
    Schema::dropIfExists('system_resource');
  }
}
